Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(metrics): consumable metrics audit output #5101

Merged
merged 5 commits into from
May 4, 2018

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented May 3, 2018

after much ado about nothing and the repeated creation/deletion of summary, we're just making a single item inside details that has all the metrics keyed by name and Ts. @paulirish approved of this approach

it means that querying will look like audits.metrics.details.items[0].firstContentfulPaint

we'll just commit to not breaking that contract with uber typechecking 🎉

ref #5008

@paulirish
Copy link
Member

@denar90 @pedro93 @benschwarz @alekseykulikov hows this look to you? you'll get all metrics within this audit instead of relying on lighthouse-core/lib/traces/pwmetrics-events.js or pulling diff numbers from various audit's extendedInfo

for (const [name, value] of Object.entries(metrics)) {
const key = /** @type {keyof UberMetricsItem} */ (name);
if (typeof value === 'undefined') {
delete metrics[key];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe copy defined values to a new metrics object to return rather than delete from the original?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for this? I'll end up just creating an empty object with no type and casting at the end which seems sad 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can do it for now. delete is just almost always a bad idea :(

On the compiler side, this isn't really type checked either, since key has to be cast and value ends up as any. We just know that undefined and a number that can be rounded are the two possible cases. I don't know a great solution, though. We'd need an Object.entries() that doesn't widen, an Array.filter() that really filters types, and an Object.fromEntries() from TC39 :)

The other option is to leave them defined as undefined. Was that bad? They'll get dropped from the JSON and we're testing against undefined anyways

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I guess it's not the end of the world to leave them undefined, will do

const values = metricsAudit.details.items.find(item => item.metricName === metricName);
return values && values[timingOrTimestamp];
const values = metricsAudit.details.items[0];
return values && values[metricName];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be a TODO, but seems like we can just get rid of this whole findValueInMetricsAuditFn thing now. If there's no metrics audit, pwmetrics can't really do much, so it could check once at the beginning. Then all the gets are just property dereferencing with the new object layout.

(metricsDefinitions might still be useful, haven't looked into it)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure TODO added

@patrickhulce
Copy link
Collaborator Author

last 📞 , any objections?

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, forgot to submit

for (const [name, value] of Object.entries(metrics)) {
const key = /** @type {keyof UberMetricsItem} */ (name);
if (typeof value === 'undefined') {
delete metrics[key];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can do it for now. delete is just almost always a bad idea :(

On the compiler side, this isn't really type checked either, since key has to be cast and value ends up as any. We just know that undefined and a number that can be rounded are the two possible cases. I don't know a great solution, though. We'd need an Object.entries() that doesn't widen, an Array.filter() that really filters types, and an Object.fromEntries() from TC39 :)

The other option is to leave them defined as undefined. Was that bad? They'll get dropped from the JSON and we're testing against undefined anyways

@patrickhulce patrickhulce merged commit 947548c into master May 4, 2018
@patrickhulce patrickhulce deleted the better_metrics_js branch May 4, 2018 22:36
@denar90
Copy link
Contributor

denar90 commented May 5, 2018

Looks nice, great work guys 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants